<?
//----------------------------------------------------------------------------------------------------
function get_all_referer_groups($type='all'){
	global $session_db_name,$dbh,$sid;
			
	$SQL = "select distinct groupname from referergroups order by groupname";
        $result = @mysql_db_query($session_db_name, $SQL, $dbh);
        
        switch($type){
        	case "select":
			while($row = @mysql_fetch_array($result)){
				$list .= "<option value='$row[groupname]'>$row[groupname]</option>\n";
			}
        	break;
        	case "all":
			while($row = @mysql_fetch_array($result)){
				$list .= "<table border='0'class='bTable' cellpadding='0' cellspacing='0' width='50%'>";
				$list .= "<tr><td colspan='3' align='center' bgcolor='#DDDDDD'>$row[groupname]</td></tr>";
				$SQL1 = "select referer, groupname from referergroups where groupname='$row[groupname]' order by referer"; 
				$result1 = @mysql_db_query($session_db_name, $SQL1, $dbh);        	
				$p = 0;
				while($row1 = @mysql_fetch_array($result1)){
					$p++;
					$list .= "<tr>
							<td>$p</td>
							<td>$row1[referer]</td>
							<td>
								<form action='' method='POST'>
									<input type='hidden' name='ref' value='$row1[referer]'>
									<input type='hidden' name='group' value='$row[groupname]'>
									<input type='hidden' name='ss' value='delRef'>
									<input type='submit'  value='Delete'>
								</form>
							</td>
						</tr>";
				}
				$list .= "</table><br><p><br>";
			}        	
        	break;
        }
	return $list;	
}
//----------------------------------------------------------------------------------------------------
function add_referer($ref,$group){
	global $session_db_name,$dbh,$sid;
	
	$SQL = "insert into referergroups (referer,groupname) values('$ref','$group')";
	if(!($result = @mysql_db_query($session_db_name, $SQL, $dbh))) return 0;
	return "1";
}
//----------------------------------------------------------------------------------------------------
function del_referer($ref,$group){
	global $session_db_name,$dbh,$sid;
	
	$SQL = "delete from referergroups where referer='$ref' and groupname='$group'";
	if(!($result = @mysql_db_query($session_db_name, $SQL, $dbh))) return 0;
	return "1";
}
//----------------------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------------------

?>